/*01背包问题*/ 

#include<stdio.h>
int max(int a,int b)
{
	if(a>b)
		return a;
	else
		return b;
}
struct friends
{
	int hp;
	int happy;
};
struct friends f[22];
int main()
{
	int n,i,j,k,dp[22][101]={0},l=0,life=100;//（life）就相当于背包的总容量 
	scanf("%d",&n);getchar();
	for(i=1;i<=n;i++)
		scanf("%d",&f[i].hp);
	
	for(i=1;i<=n;i++)
		scanf("%d",&f[i].happy);
		
	f[0].hp=0;
	f[0].happy=0;
	
		
	for(i=1;i<=n;i++)
	{
		for(j=1;j<life;j++)
		{
			if(j<=f[i].hp)//这一步装不下，所以不用装的结果，而下面将分为两种结果 
				dp[i][j]=dp[i-1][j];
			else
				dp[i][j] = max ( dp[i-1][j] , dp[i-1][j-f[i].hp] + f[i].happy );
			//printf("%d ",dp[i][j]);
		}
		//printf("\n");
	}
	printf("%d\n",dp[n][life-1]);
	return 0;
}










